# 导入unittest模块
import unittest
import os,wmi,hashlib,sys

import cryptocode
import fdb
 
# 创建一个测试类，继承自unittest.TestCase

from lib import config


class MyTests(unittest.TestCase):

    # 定义测试方法
    def test_addition(self):
        # 断言两个数字相加的结果
        self.assertEqual(1 + 1, 2)

    def test_subtraction(self):
        self.assertEqual(3 - 1, 2)

    def test_cpu_serial(self):
        c = wmi.WMI()
        cpu =  c.Win32_Processor()[0]
        print(cpu.ProcessorId.strip())

    def encryptAppcodekey(self,encryptString):
        c = wmi.WMI()
        cpu = c.Win32_Processor()[0]
        secret_key = cpu.ProcessorId.strip()
        decryptString1 = cryptocode.encrypt(encryptString, secret_key)
        decryptString2 = cryptocode.encrypt(decryptString1, secret_key)
        # print(decryptString2)
        return decryptString2


    def test_key(self):
        print("---------------")
        encrypt = 'BFEBFBFF000306C3||bdsendpack||20240131'
        key = self.encryptAppcodekey(encrypt)
        print(key)

    # https: // blog.csdn.net / bq_cui / article / details / 81265374
    def test_fdb(self):
        import fdb
        rootPath = os.path.abspath('../')
        # 定义数据库文件路径
        db_path = rootPath + '\\data\\esonseo.dat'

        # 连接到数据库
        con = fdb.connect(dsn=db_path,user='SYSDBA',password='eade61eddatabase2')
        # 创建一个游标对象
        cur = con.cursor()
        cur.execute("SELECT 1 FROM rdb$relations WHERE rdb$relation_name = 'employees'")
        table_exists = cur.fetchone() is not None
        if not table_exists:
            print("not exists")
        else:
            print("exists")

        #创建一个表
        # cur.execute("""
        #     CREATE TABLE employees (  id INT PRIMARY KEY,  name VARCHAR(50) );
        # """)
        # con.commit()
        # # 插入数据
        # cur.execute("INSERT INTO employees (id, name) VALUES (1, 'Alice')")
        # cur.execute("INSERT INTO employees (id, name) VALUES (2, 'Bob')")

        # 提交事务
        con.commit()

        # 查询数据
        cur.execute("SELECT * FROM employees")
        for row in cur:
            print(row)

        # 关闭游标和连接
        cur.close()
        con.close()



# 创建一个测试运行器
if __name__ == '__main__':
    unittest.main()
